package com.xhd.db;

import com.xhd.exception.DatabaseException;

public class DaoTransaction {

	  private DBCenter[] jm403 = new DBCenter[4];
	  private String[] jm404 = new String[4];
	  private int jm405 = 0;
	  private boolean jm406 = true;

	  public synchronized void add(DBCenter paramDBCenter, String paramString)
	  {
	    if (this.jm405 > this.jm403.length)
	    {
	      DBCenter[] arrayOfDBCenter = this.jm403;
	      this.jm403 = new DBCenter[this.jm403.length + 2];
	      for (int i = 0; i < arrayOfDBCenter.length; ++i)
	        this.jm403[i] = arrayOfDBCenter[i];
	      arrayOfDBCenter = (DBCenter[])null;
	    }
	    this.jm403[this.jm405] = paramDBCenter;
	    this.jm404[this.jm405] = paramString;
	    this.jm405 += 1;
	  }

	  public DBCenter get(String paramString)
	  {
	    if (paramString == null)
	      return null;
	    for (int i = 0; i < this.jm405; ++i)
	      if (paramString.equals(this.jm404[i]))
	        return this.jm403[i];
	    return null;
	  }

	  public void commit()
	    throws DatabaseException
	  {
	    for (int i = 0; i < this.jm405; ++i)
	      this.jm403[i].commit();
	    BizObjStoreListener.getInstance().jm410();
	  }

	  public void rollback()
	  {
	    for (int i = 0; i < this.jm405; ++i)
	      this.jm403[i].rollback();
	    BizObjStoreListener.getInstance().jm411();
	  }

	  public void close()
	  {
	    for (int i = 0; i < this.jm405; ++i)
	    {
	      this.jm403[i].freeConnection();
	      this.jm403[i] = null;
	    }
	    this.jm405 = 0;
	  }

	  public int getConnCount()
	  {
	    int i = 0;
	    for (int j = 0; j < this.jm405; ++j)
	      i += this.jm403[j].getDBConnCount();
	    return i;
	  }

	  public String getUseInfo(boolean paramBoolean)
	  {
	    StringBuffer localStringBuffer = new StringBuffer(128);
	    for (int i = 0; i < this.jm405; ++i)
	    {
	      if (i > 0)
	        localStringBuffer.append("\r\n");
	      localStringBuffer.append(this.jm403[i].getUseInfo(paramBoolean));
	    }
	    return localStringBuffer.toString();
	  }

	  public int kill()
	  {
	    int i = 1;
	    for (int j = 0; j < this.jm405; ++j)
	    {
	      i = this.jm403[j].kill();
	      if (2 != i)
	        return i;
	    }
	    return i;
	  }

	  public void setTransation(boolean paramBoolean)
	  {
	    this.jm406 = paramBoolean;
	    for (int i = 0; i < this.jm405; ++i)
	      this.jm403[i].setTransation(paramBoolean);
	  }

	  public boolean isUsedTransation(DBCenter paramDBCenter)
	  {
	    return this.jm406;
	  }

	  public boolean isClosed()
	  {
	    return (this.jm405 < 1);
	  }
}
